$("#startDate").focus(function () {
    WdatePicker({
        skin: 'twoer',
        dateFmt: 'yyyy-MM-dd',
        readOnly: true,
        isShowToday: false,
        onpicked: function () {
            var endDate = $('#endDate').val();
            if (endDate) {
                curEl.bootstrapTable("refresh");
            }
            $dp.$('endDate').focus();
        }
    });
});

$("#endDate").focus(function () {
    var me = $(this);
    WdatePicker({
        skin: 'twoer',
        dateFmt: 'yyyy-MM-dd',
        readOnly: true,
        isShowToday: false,
        minDate: '#F{$dp.$D(\'startDate\')}',
        onpicked: function () {
            curEl.bootstrapTable("refresh");
            // 手动失去焦点，便于再次选中
            me.blur();
        }
    });
});

$("#keyword").on("keyup", function (event) {
    if (event.keyCode == 13) {
        curEl.bootstrapTable("refresh");
    }
});

var statusArr = [{"id": 0, "name": "禁用"}, {"id": 1, "name": "启用"}];

$('#status').combobox({
    id: "status",
    data: statusArr,
    onChange: function() {
        curEl.bootstrapTable("refresh");
    }
});

$("#add").on("click", function () {
    $.showPage("", "添加", webRoot + "/console/systemUsers/add.html");
});

var curEl = $("#systemUsersTable");
curEl.initTable({
    url: webRoot + '/console/systemUsers',
    columns: systemUserColumns(),
    isPagination: true,
    extraParamsDom: {
        keyword: $("#keyword"),
        status: $("#status"),
        startDate: $("#startDate"),
        endDate: $("#endDate")
    },
    buttons: [{
        id: "edit",
        btnClass: "btn btn-default btn-xs purple",
        icon: "fa fa-edit",
        name: "编辑",
        handler: function (row) {
            $.showPage("", "编辑", webRoot + "/console/systemUsers/edit.html?id=" + row.id);
        }
    }, {
        id: "assignRole",
        btnClass: "btn btn-default btn-xs purple",
        icon: "fa fa-edit",
        name: "分配角色",
        hidden: function(row) {
            return !row.status;
        },
        handler: function (row) {
            $.showPage("", "编辑", webRoot + "/console/systemUsers/assignRole.html?id=" + row.id);
        }
    }]
});